import javax.swing.*;
import java.awt.*;
import java.util.LinkedList;

public class MedusaObjectManager {
    LinkedList<AbstractBiology> enemyLinked = new LinkedList<AbstractBiology>();

    public void render(Graphics g, Maps maps, DoraemonObjectManager doraemonObjectManager) {
        g.setColor(Color.red);
        for (int i = 0; i < enemyLinked.size(); i++) {
            AbstractBiology tempObject = enemyLinked.get(i);
            tempObject.render(g, maps, doraemonObjectManager, this);
        }
    }

    public void tick() {
        for (int i = 0; i < enemyLinked.size(); i++) {
            AbstractBiology tempObject = enemyLinked.get(i);
            tempObject.tick();
        }
        isMonsterDeath();
        getCurrentPlayer();
    }

    public void isMonsterDeath() {
        for (int i = 0; i < enemyLinked.size(); i++) {
            if (enemyLinked.get(i).getHP() <= 0) {
                enemyLinked.remove(i);
                JOptionPane.showMessageDialog(null, "Monster Death");
            }
        }
    }

    public void enemyMove(Maps maps, GameStats gameStats, java.awt.event.MouseEvent e, DoraemonObjectManager doraemonObjectManager, MedusaObjectManager medusaObjectManager, Thread thread) throws InterruptedException {
        for (int i = 0; i < enemyLinked.size(); i++) {
            AbstractBiology tempObject = enemyLinked.get(i);
            tempObject.enemyMove(maps, doraemonObjectManager, medusaObjectManager, thread);
            //Thread.sleep(1000);
        }
        gameStats.CURRENTSTATS = gameStats.PLAYERTURN;
        maps.setCurrentTurnBaseStats(TurnBaseStats.playerturn);
        Thread.sleep(2000);
        maps.setCurrentTurnBaseStats(TurnBaseStats.nothing);
        //JOptionPane.showMessageDialog(null,"玩家的回合");
    }

    public int getcurrentenemy = 0;

    public void getCurrentPlayer() {
        for (int i = 0; i < enemyLinked.size(); i++) {
            if (enemyLinked.get(i).isSelected()) {
                getcurrentenemy = i;
            }
        }
    }

    public boolean isHaveEnmeyInHereMouseE(java.awt.event.MouseEvent e, Maps maps) {
        for (int i = 0; i < enemyLinked.size(); i++) {
            if (e.getY() / Global.CELL_SIZE == enemyLinked.get(i).getX() + maps.offsetY &&
                    e.getX() / Global.CELL_SIZE == enemyLinked.get(i).getY() + maps.offsetX) {

                enemyLinked.get(i).setHP(enemyLinked.get(i).getHP() - 10);
                System.out.println("attack");

                return true;
            }
        }
        return false;
    }

    public boolean isHaveEnmeyInHere(int x, int y) {
        for (int i = 0; i < enemyLinked.size(); i++) {
            if (x == enemyLinked.get(i).getX() && y == enemyLinked.get(i).getY()) {
                return true;
            }
        }
        return false;
    }

    public void addPlayer(AbstractBiology object) {
        this.enemyLinked.add(object);
    }

    public void removePlayer(AbstractBiology object) {
        this.enemyLinked.remove(object);
    }
}

